package com.way;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 开启异步线程，等待结果执行完
 *
 * @author 魏彪
 */
public class Test01 implements Callable<String> {
    public static void main(String[] args) {
        FutureTask<String> futureTask = new FutureTask<>(new Test01());

        new Thread(futureTask).start();

        try {
            String result = futureTask.get();
            System.out.println(result);
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }

        System.out.println("main线程执行");
    }

    @Override
    public String call() throws Exception {
        return "Thread executed finish";
    }
}
